﻿using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace LD.Host
{
    public partial class FrmLogHis : DockContent
    {
        public FrmLogHis()
        {
            InitializeComponent();
        }

        private void btn_query_Click(object sender, EventArgs e)
        {
            this.dgv_list.Rows.Clear();
        }

        private void btn_output_Click(object sender, EventArgs e)
        {
            if (this.dgv_list.Rows.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                string fileName = string.Empty;
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.Filter = "txt|*.txt";
                    sfd.RestoreDirectory = true;
                    sfd.FileName = "log";
                    sfd.CheckPathExists = true;
                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        fileName = sfd.FileName;
                       
                        if (sb.Length > 0 && !string.IsNullOrEmpty(fileName))
                        {
                            FileStream fs1 = new FileStream(fileName, FileMode.Create, FileAccess.Write);//创建写入文件  
                            StreamWriter sw = new StreamWriter(fs1);
                            sw.WriteLine(sb.ToString());//开始写入值 
                            sw.Close();
                            fs1.Close();
                        }

                        MessageBox.Show("汇出完成", "信息");
                    }
                }
            }
        }
    }
}
